package net.maku.events.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.maku.events.entity.UserJoinActivityEntity;
import net.maku.events.entity.UserPointsRecordsEntity;
import net.maku.events.query.ActivityRankQuery;
import net.maku.events.vo.RankMemberUserVO;
import net.maku.events.vo.RankOrgVO;
import net.maku.framework.mybatis.dao.BaseDao;
import net.maku.talent.entity.HonorCommunityEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * @Author: qr
 * @Date: 2025/3/25 22:12
 * @Version 1.0
 */
@Mapper
public interface UserPointsRecordsDao extends BaseDao<UserPointsRecordsEntity> {

    /**
     * 获取个人排行榜
     *
     * @param query 查询条件
     * @return 结果
     */
    RankMemberUserVO userSelfRank(@Param("query") ActivityRankQuery query,@Param("targetUserId")Long targetUserId);

    /**
     * 获取个人排行榜
     *
     * @param businessId   活动id
     * @param businessType 活动类型
     * @param todayFlag    是否今日排行榜
     * @return 结果
     */
    List<RankMemberUserVO> getRank(@Param("businessId") Long businessId, @Param("businessType") Integer businessType, @Param("todayFlag") boolean todayFlag);

    /**
     * 获取个人排行榜
     *
     * @param pageParams 分页数据
     * @param query      查询条件
     * @return 结果
     */
    IPage<RankMemberUserVO> getRankPage(@Param("page") IPage<UserJoinActivityEntity> pageParams, @Param("query") ActivityRankQuery query);


    /**
     * 获取单位排行榜
     *
     * @param businessId   活动id
     * @param businessType 活动类型
     * @return 结果
     */
    List<RankOrgVO> getRankOrg(@Param("businessId") Long businessId, @Param("businessType") Integer businessType);

    /**
     * 获取该单位下的
     *
     * @param orgIdList 活动id
     * @return 结果
     */
    List<RankOrgVO> getRankOrg(@Param("businessId") List<Long> orgIdList);

    /**
     * 生成个人排行快照
     * @param businessId
     * @param businessType
     */
    void generateRankSnapshot(@Param("businessId") Long businessId, @Param("businessType") Integer businessType);

    /**
     * 生成个人排行快照
     * @param businessId
     * @param businessType
     */
    void generateRankSnapshotToday(@Param("businessId") Long businessId, @Param("businessType") Integer businessType, @Param("todayFlag") boolean todayFlag);

    /**
     * 生成个人排行快照
     * @param businessId
     * @param businessType
     */
    void generateOrgRankSnapshot(@Param("businessId") Long businessId, @Param("businessType") Integer businessType);


    /**
            * 强制物理删除（绕过逻辑删除）
            * @param userId 用户ID
     * @return 删除的行数
     */
    @Delete("DELETE FROM user_points_records WHERE user_id = #{userId}")
    int forceDeleteByUserId(@Param("userId") Long userId);
}
